import { defineStore } from 'pinia';

interface ObjectList {
	[key: string]: string[];
}

export const usePermissStore = defineStore('permiss', {
	state: () => {
		return {
			hasRoutes: false,
			token: '',
			menuList: [{}],
			currentUser: {},
			authorityStr: '',
			userSrc:''
		};
	},
	actions: {
		setRouteState(val: boolean) {
			this.hasRoutes = val
		},
		setToken(token: string) {
			this.token = token
			sessionStorage.setItem("token", token)
		},
		getToken() {
			return sessionStorage.getItem("token")
		},
		setMenuList(menuList: Array<Object>) {
			this.menuList = menuList;
			sessionStorage.setItem("menuList", JSON.stringify(menuList));
		},
		getMenuList() {
			return JSON.parse(sessionStorage.getItem("menuList") || "");
		},
		setCurrentUser(currentUser: Object) {
			this.currentUser = currentUser;
			sessionStorage.setItem("currentUser", JSON.stringify(currentUser));
		},
		getCurrentUser() {
			return JSON.parse(sessionStorage.getItem("currentUser") || "");
		},
		setAuthorityStr(authorityStr: string) {
			this.authorityStr = authorityStr;
			sessionStorage.setItem("authority", authorityStr);
		},
		getAuthorityStr() {
			return sessionStorage.getItem("authorityStr")
		},
		setUserSrc(userSrc: string) {
			this.userSrc = userSrc;
		},
		getUserSrc() {
			return this.userSrc
		}
	}
});
